/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package torrent;

import java.net.DatagramPacket;
import java.net.InetAddress;

/**
 *
 * @author THIEUQUANG
 */
public class broadcastsender extends Function implements Runnable {

    String Messagetosend;

    public broadcastsender(String Messagetosend) {
        this.Messagetosend = Messagetosend;
    }

    public void run() {
        try {

            while (true) {
                byte[] sentBuf = new byte[100];
                System.out.println("Broadcasting");
                //InetAddress broadcast = InetAddress.Broadcast;

                InetAddress sentHost = InetAddress.getByName("255.255.255.255");
                sentBuf = Messagetosend.getBytes("ascii");
                utpSocket2.setBroadcast(true);

                DatagramPacket sentPacket = new DatagramPacket(sentBuf,
                        sentBuf.length, sentHost, 3400);
                utpSocket2.send(sentPacket);
                break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
